package demo0526;

import java.util.Objects;

//员工类
public class Emp {
    private String number; // 员工编号
    private String name;   // 员工姓名
    private int age;       // 员工年龄

    // 构造方法
    public Emp(String number, String name, int age) {
        this.number = number;
        this.name = name;
        this.age = age;
    }

    // Getter和Setter方法
    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    // 重写equals和hashCode方法，确保Set集合能正确判断对象相等性
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Emp emp = (Emp) o;
        return age == emp.age &&
                Objects.equals(number, emp.number) &&
                Objects.equals(name, emp.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(number, name, age);
    }

    // 重写toString方法，方便打印员工信息
    @Override
    public String toString() {
        return "Emp{" +
                "number='" + number + '\'' +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
